package com.baseframe.system.entity.vo;

import cn.hutool.core.lang.tree.Node;
import com.baseframe.system.entity.BaseMenu;
import com.baseframe.tool.utils.data.NodeUtil;
import com.baseframe.tool.utils.data.Tree;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@Getter
@Setter
@ToString
@EqualsAndHashCode(callSuper = true)
public class BaseMenuVO extends NodeUtil.Node<BaseMenuVO>{
    private Long id;
    private String name;
    private List<BaseMenuVO> childNode;
    private String icon;

    private String router;

    private Integer sort;

    private Long parent;

    private Integer type;

    private String remarks;



    public List<BaseMenuVO> build(List<BaseMenu> baseMenus){

        List<BaseMenuVO> baseMenuVOS = new ArrayList<>();








        return null;
    }


//    public static List<BaseMenuVO> buildMenu(List<BaseMenu> baseMenus){
//        List<BaseMenuVO> parentVOList = new ArrayList<>();
//
//        parentVOList = baseMenus.stream().filter(e->e.getParent()==null).map(e->{
//            BaseMenuVO parentVO = new BaseMenuVO();
//            BeanUtils.copyProperties(e,parentVO);
//
//            return parentVO;
//        }).collect(Collectors.toList());
//        //整理父接单的所有子节点并排序
//        for (BaseMenuVO parentMenuVO : parentVOList) {
//            List<BaseMenuVO> node = new ArrayList<>();
//            for (BaseMenu baseMenu : baseMenus) {
//                if (Objects.equals(parentMenuVO.getId(),baseMenu.getParent())){
//                    BaseMenuVO childMenu = new BaseMenuVO();
//                    BeanUtils.copyProperties(baseMenu,childMenu);
//                    node.add(childMenu);
//                }
//            }
//
//            //子节点排序
//            node = node.stream().sorted(Comparator.comparing(BaseMenuVO::getSort)).collect(Collectors.toList());
//            parentMenuVO.setChildNode(node);
//        }
//
//
//
//
//        return parentVOList;
//    }

    public static void main(String[] args) {
        BaseMenuVO baseMenu = new BaseMenuVO();
        baseMenu.setId(1L);
        baseMenu.setName("首页");
        baseMenu.setSort(1);

        BaseMenuVO baseMenu2 = new BaseMenuVO();
        baseMenu2.setId(2L);
        baseMenu2.setName("系统设置");
        baseMenu2.setSort(1);

        BaseMenuVO baseMenu4 = new BaseMenuVO();
        baseMenu4.setId(4L);
        baseMenu4.setName("角色设置");
        baseMenu4.setSort(2);
        baseMenu4.setParent(2L);

        BaseMenuVO baseMenu3 = new BaseMenuVO();
        baseMenu3.setId(3L);
        baseMenu3.setName("权限设置");
        baseMenu3.setSort(1);
        baseMenu3.setParent(2L);

        BaseMenuVO baseMenu5 = new BaseMenuVO();
        baseMenu5.setId(4L);
        baseMenu5.setName("权限设置2");
        baseMenu5.setSort(1);
        baseMenu5.setParent(3L);



        List<BaseMenuVO> baseMenuList = new ArrayList<>();

        baseMenuList.add(baseMenu2);
        baseMenuList.add(baseMenu3);

        baseMenuList.add(baseMenu5);
        baseMenuList.add(baseMenu);
        baseMenuList.add(baseMenu4);


        List<BaseMenuVO> tree = NodeUtil.warpTree(baseMenuList);


        for (BaseMenuVO baseMenuVO : tree) {
            System.out.println(baseMenuVO);
        }

//        List<BaseMenuVO> baseMenuVOS = buildMenu(baseMenuList);
//
//        for (BaseMenuVO baseMenuVO : baseMenuVOS) {
//            System.out.println(baseMenuVO);
//        }

    }



}
